﻿using System;
using System.Data;
using System.Collections.Generic;
using DataLib.Common;
using DataLib.Model;
namespace DataLib.BLL
{
	/// <summary>
	/// LoadNum
	/// </summary>
	public partial class LoadNum
	{
		private readonly DataLib.DAL.LoadNum dal=new DataLib.DAL.LoadNum();
		public LoadNum()
		{}
		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int? id)
		{
			return dal.Exists(id);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(DataLib.Model.LoadNum model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(DataLib.Model.LoadNum model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int? id)
		{
			
			return dal.Delete(id);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			return dal.DeleteList(idlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public DataLib.Model.LoadNum GetModel(int? id)
		{
			
			return dal.GetModel(id);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public DataLib.Model.LoadNum GetModelByCache(int? id)
		{
			
			string CacheKey = "LoadNumModel-" + id;
			object objModel = DataLib.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(id);
					if (objModel != null)
					{
						int ModelCache = DataLib.Common.ConfigHelper.GetConfigInt("ModelCache");
						DataLib.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (DataLib.Model.LoadNum)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<DataLib.Model.LoadNum> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<DataLib.Model.LoadNum> DataTableToList(DataTable dt)
		{
			List<DataLib.Model.LoadNum> modelList = new List<DataLib.Model.LoadNum>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				DataLib.Model.LoadNum model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = dal.DataRowToModel(dt.Rows[n]);
					if (model != null)
					{
						modelList.Add(model);
				}
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  BasicMethod
		#region  ExtensionMethod
               /// <summary>
        /// 获取所有废弃物的Load数据集
        /// </summary>
        /// <returns></returns>
        public DataTable GetLoadKH()
        {
            return dal.GetLoadKH();
        }

        public DataTable GetLoadKHBywhere(string where)
        {
            return dal.GetLoadKHBywhere(where);
        }
               /// <summary>
        /// 根据Load号获取Model
        /// </summary>
        /// <param name="loadno">LOAD号</param>
        /// <returns></returns>
        public Model.LoadNum GetLoadID(string loadno)
        {
            return dal.GetLoadID(loadno);
        }

        /// <summary>
        /// 拆解 生产
        /// </summary>
        /// <param name="loadno"></param>
        /// <param name="flag"></param>
        /// <returns></returns>
        public string GetCusm(string loadno,int flag)
        {
            string str = "";
            if (loadno.IndexOf("XN") == 0)
            {
                str = "运营仓库";
            }
            else if (loadno.IndexOf("86") != 0)
            {
                str = "伟翔仓库";
            }
            else
            {
                Model.LoadNum model = GetLoadID(loadno);

                
                if (model != null)
                {
                    if (flag == 1)
                        str = model.cumname;

                    else
                        str = model.cumcode;
                }

            }
            return str;
        }

        public string GetCusm(Model.OutStorage oModel)
        {
            string str = "";



            if ((oModel.belogarea == oModel.inDepart) && (oModel.graphicCity != oModel.outStorageType))
            {
                if (oModel.StorageType == "原料库")
                    str = GetCusm(oModel.VLoadNum, 1);
                else
                    str = oModel.belogarea + oModel.OutDepart + "库";
            }
            else
            {
                str = oModel.inDepart + "伟翔";
            }
            return str;
        }

               /// <summary>
        /// 取得Load节点
        /// </summary>
        /// <param name="no"></param>
        /// <returns></returns>
        public DataTable GetTreeVieww(string no,string notype)
        {
            return dal.GetTreeVieww(no,notype);
        }

        
        /// <summary>
        /// 显示Load单下面所有CJO的显示人员
        /// </summary>
        /// <param name="loadid"></param>
        /// <returns></returns>
        public string SalemanByLoad(int loadid)
        {
            return dal.SalemanByLoad(loadid);
        }

               /// <summary>
        /// 根据Loadid取项目ID
        /// </summary>
        /// <param name="loadid"></param>
        /// <returns></returns>
        public int GetProidByLoadid(string loadid)
        {
            return dal.GetProidByLoadid(loadid);
        }
		#endregion  ExtensionMethod
	}
}

